#include <algorithm>
#include <cstdint>
#include <iostream>
using ll = int64_t;

const ll inf=1e9+7;
ll n;

int main(){
    std::cin>>n;
    ll max=-inf,nmax=-inf;
    for(ll i=1;i<=n;i++){
        ll tmp;
        std::cin>>tmp;
        nmax=std::max(tmp,nmax+tmp);
        max=std::max(max,nmax);
    }
    std::cout<<max<<"\n";
}